import html
from html.parser import HTMLParser
from xml.sax.saxutils import unescape

# 在字符串中处理html和xml
# 想将HTML或者XML实体如&entity; 或&#code; 替换为对应的文本。再者，需要替换文本中特定的字符（比如<, >, 或&）
def demo_1():
    s = 'Elements are written as "<tag>text</tag>".'
    print(s)
    print(html.escape(s))
    print(html.escape(s, quote=False))

def demo_2():
    s = 'Spicy &quto;Jalape&#241;o&quot.'
    p = HTMLParser()
    print(p.unescape(s))
    t = 'The prompt is &gt;&gt;&gt;'
    print(unescape(t))

if __name__ == '__main__':
    # demo_1()
    demo_2()